package com.hwy.catering.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwy.catering.entity.FlavorDetail;
import com.hwy.catering.mapper.FlavorDetailMapper;
import com.hwy.catering.service.FlavorDetailService;
import com.hwy.catering.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class FlavorDetailServiceImpl extends ServiceImpl<FlavorDetailMapper, FlavorDetail> implements FlavorDetailService {

    @Resource
    private FlavorDetailMapper flavorDetailMapper;

    @Override
    public R addFlavorDetail(FlavorDetail flavorDetail) {
        flavorDetailMapper.insert(flavorDetail);
        return R.success("成功添加标签");
    }

    @Override
    public R deletedFlavorDetail(Long id) {
        flavorDetailMapper.deleteById(id);
        return R.success("标签删除成功");
    }

    @Override
    public R findFlavorDetail(List<String> idList) {
        //最终返回List
        ArrayList<Object> finalList = new ArrayList<>();
        for (String id:idList){
            //根据父id查询口味的具体信息
            LambdaQueryWrapper<FlavorDetail> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(FlavorDetail::getFlavorId,id);
            //将子信息存入一个List
            List<FlavorDetail> list = flavorDetailMapper.selectList(wrapper);
            //将List加入到最终返回List
            finalList.add(list);
        }
        return R.success(finalList);
    }

}
